package com.roc.learn.goodgoodstudy.algorithms;

/**
 * 冒泡排序
 * O(n log n)
 */
public class BubbleSort {

    public static void main(String[] args) {
        int[] array = {6, 1, 2, 7, 9, 11, 4, 5, 10, 8};
        BubbleSort(array);
        for (int a : array) {
            System.out.print(a + ",");
        }
        System.out.println(",");

    }

    /**
     * 教学
     */

    public static void BubbleSort(int[] array) {
        for (int i = 0; i < array.length - 1; i++) {
            for (int j = 0; j < array.length - 1 - i; j++) {
                if (array[j] > array[j + 1]) {
                    int temp = array[j + 1];
                    array[j + 1] = array[j];
                    array[j] = temp;
                }
            }
        }
    }


    /**
     * 练习1

     */


}
